"""
Room database model.
"""
import uuid
from sqlalchemy import Column, String, Integer, JSON, Enum as SQLEnum
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from datetime import datetime
from sqlalchemy import DateTime
from app.database import Base
import enum


class RoomStatus(str, enum.Enum):
    """Room status enumeration."""
    ACTIVE = "active"            # 使用小写，与前端保持一致
    INACTIVE = "inactive"        # 使用小写，与前端保持一致
    MAINTENANCE = "maintenance"  # 使用小写，与前端保持一致


class Room(Base):
    """Meeting room model."""
    
    __tablename__ = "rooms"
    
    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    name = Column(String(100), unique=True, nullable=False, index=True)
    capacity = Column(Integer, nullable=False)
    location = Column(String(200), nullable=False)
    facilities = Column(JSON, default=list)  # List of available facilities
    status = Column(SQLEnum(RoomStatus), default=RoomStatus.ACTIVE, nullable=False)
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
    
    # Relationships
    bookings = relationship("Booking", back_populates="room", cascade="all, delete-orphan")
    schedules = relationship("Schedule", back_populates="room", cascade="all, delete-orphan")
    
    def __repr__(self):
        return f"<Room {self.name} (Capacity: {self.capacity})>"
